package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;

import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 分页查询
     * @param ordersPageQueryDTO
     * @return com.sky.result.Result<java.util.List<com.sky.vo.OrderVO>>
     * @author zhupp
     * @create 2025/2/26
     **/
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("开始订单分页查询");
        PageResult list = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(list);
    }

    /**
     * 各个状态的订单数量统计
     * @return com.sky.result.Result<com.sky.vo.OrderStatisticsVO>
     * @author zhupp
     * @create 2025/2/26
     **/
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getOrderStatistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.getOrderStatistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查询订单详情
     * @param OrderId
     * @return com.sky.result.Result<com.sky.vo.OrderVO>
     * @author zhupp
     * @create 2025/2/26
     **/
    @GetMapping("details/{id}")
    public Result<OrderVO> getOrder(@PathVariable("id") Long OrderId) {
        OrderVO orderVO = orderService.getOrder(OrderId);
        return Result.success(orderVO);
    }

    /**
     * 接单
     * @param ordersConfirmDTO
     * @return com.sky.result.Result<java.lang.String>
     * @author zhupp
     * @create 2025/2/26
     **/
    @PutMapping("/confirm")
    public Result<String> confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return com.sky.result.Result<java.lang.String>
     * @author zhupp
     * @create 2025/2/26
     **/
    @PutMapping("/rejection")
    public Result<String> rejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        orderService.rejectOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return com.sky.result.Result<java.lang.String>
     * @author zhupp
     * @create 2025/2/26
     **/
    @PutMapping("/cancel")
    public Result<String> cancelOrderAdmin(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        orderService.cancelOrderAdmin(ordersCancelDTO);
        return Result.success();
    }

    /*
     * 派送订单
     * @param id
     * @return com.sky.result.Result<java.lang.String>
     * @author zhupp
     * @create 2025/2/26
     **/
    @PutMapping("/delivery/{id}")
    public Result<String> deliveryOrder(@PathVariable Long id) throws Exception {
        orderService.deliveryOrder(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param OrderId
     * @return com.sky.result.Result<java.lang.String>
     * @author zhupp
     * @create 2025/2/26
     **/
    @PutMapping("/complete/{id}")
    public Result<String> completeOrder(@PathVariable("id") Long OrderId) throws Exception {
        orderService.completeOrder(OrderId);
        return Result.success();
    }
}
